use std::collections::{BTreeMap, HashMap};

pub fn flatten01() {
    println!("--------flatten01--------");
    let mut cities = BTreeMap::new();
    cities.insert("Guangxi", vec!["Nanning", "Liuzhou", "Guilin"]);
    cities.insert("Guangdonng", vec!["Shenzhen", "Guangzhou", "Dongguan"]);
    cities.insert("Hubei", vec!["Wuhan", "Jingzhou", "Yichang"]);
    let all_cities: Vec<_> = cities.values().flatten().cloned().collect();
    println!("{:?}", all_cities);
}

pub fn flat_map01() {
    println!("--------flat_map01--------");
    let mut major_cities = HashMap::new();
    major_cities.insert("Japan", vec!["Tokyo", "Kyoto"]);
    major_cities.insert("US", vec!["Portland", "Mashville"]);
    major_cities.insert("Brazil", vec!["Sao Paulo", "Brasilia"]);
    major_cities.insert("China", vec!["Shanghai", "Beijing"]);

    let countries = ["Japan", "US", "Brazil", "China"];

    for &city in countries.iter().flat_map(|country| &major_cities[country]) {
        println!("{}", city)
    }
}